package klochkov.snake.common;

public enum  Direction {
	UP(0), 
	RIGTH(1), 
	DOWN(2), LEFT(3);

	private final int value;

	Direction(int value) {
		this.value = value;
	}

	public Direction turnLeft() {
		int dir = this.value - 1;
		if (dir < 0)
			dir = 3;
		return getDirection(dir);
	}
	public Direction turnRight() {
		int dir = this.value + 1;
		if (dir > 3)
			dir = 1;
		return getDirection(dir);
	}

	private Direction getDirection(int dirValue) {
		switch (dirValue) {
		case 0:
			return Direction.UP;
		case 1:
			return Direction.RIGTH;
		case 2:
			return Direction.DOWN;
		case 3:
			return Direction.LEFT;
		default:
			return null;
		}
	}
}